package com.google.code.jtasks.bugzilla.fields;

/**
 * Enumerates the standard resolutions that are unmodifiable and common to all Bugzilla servers.
 */
public enum BugzillaStandardResolution
{
	UNRESOLVED("", false),
	FIXED("FIXED", true),
	DUPLICATE("DUPLICATE", true);

	private final String label;
	private final boolean isResolved;

	/**
	 * Used by the {@link BugzillaStandardResolution} constants to construct "new instances."
	 * 
	 * @param label
	 *            the unique text that identifies/represents this {@link BugzillaStandardResolution}
	 * @param isResolved
	 *            <code>true</code> if bugs with this {@link BugzillaStandardResolution} can be considered
	 *            resolved, <code>false</code> if they are not
	 */
	private BugzillaStandardResolution(String label, boolean isResolved)
	{
		this.label = label;
		this.isResolved = isResolved;
	}

	/**
	 * Returns the unique text that identifies/represents this {@link BugzillaStandardResolution}.
	 * 
	 * @return the unique text that identifies/represents this {@link BugzillaStandardResolution}
	 */
	public String getLabel()
	{
		return label;
	}

	/**
	 * Returns <code>true</code> if bugs with this {@link BugzillaStandardResolution} can be considered
	 * resolved, <code>false</code> if they are not. Please note that this is probably only ever going to be
	 * <code>true</code> for {@link #UNRESOLVED}. Even a "<code>LATER</code>" resolution is still "temporarily
	 * resolved."
	 * 
	 * @return <code>true</code> if bugs with this {@link BugzillaStandardResolution} can be considered
	 *         resolved, <code>false</code> if they are not
	 */
	public boolean isResolved()
	{
		return isResolved;
	}

	/**
	 * Returns the {@link BugzillaStandardResolution} with the specified {@link #getLabel()}, or
	 * <code>null</code> if no matching {@link BugzillaStandardResolution} can be found.
	 * 
	 * @param label
	 *            the {@link #getLabel()} value to match
	 * @return the {@link BugzillaStandardResolution} with the specified {@link #getLabel()}, or
	 *         <code>null</code> if no matching {@link BugzillaStandardResolution} can be found
	 */
	public static BugzillaStandardResolution getResolution(String label)
	{
		for (BugzillaStandardResolution resolution : BugzillaStandardResolution.values())
			if (resolution.label.equals(label))
				return resolution;

		return null;
	}
}
